import { useEffect } from 'react';

import { Router } from 'next/router';

export const useChangeRoute = (callback: () => void) => {
  useEffect(() => {
    Router.events.on('routeChangeComplete', callback);
    Router.events.on('routeChangeStart', callback);
    return () => {
      Router.events.off('routeChangeComplete', callback);
      Router.events.off('routeChangeStart', callback);
    };
  });
};
